package com.kay.springbootRESTful.controller;

import com.kay.springbootRESTful.service.AccountService;
import com.kay.springbootRESTful.entity.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @Author Kay
 * @Date: 2019/12/12 14:51
 */

@RestController
@RequestMapping("account")
public class AccountController {

    @Autowired
    private AccountService accountService;

    @PostMapping("save")
    @ResponseStatus(code = HttpStatus.CREATED)
    public Account save(Integer customerId, @RequestBody Account account) {
        return accountService.save(customerId, account);
    }

    @PutMapping("update")
    public ResponseEntity<Account> update(Integer customerId, @RequestBody Account newAccount) {
        return accountService.update(customerId, newAccount);
    }

    @GetMapping("findAll")
    public Page<Account> findAll(Integer customerId, Pageable pageable) {
        return accountService.findAll(customerId, pageable);
    }

    @DeleteMapping("delete")
    public ResponseEntity<?> delete(Integer customerId, Integer accountNumber) {
        return accountService.delete(customerId, accountNumber);
    }
}
